home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 352_01 / strppcut.cpp < prev    next >
C/C++ Source or Header  |  1991-04-28  |  752b  |  27 lines

  1. // STRPPCUT.CPP
  2. //        contains String::cut.
  3. //        routine to remove portion of a string from middle.
  4. //        input string:    abcdefghi0
  5. //            positions:   0123456789        n =9 letters in string.
  6. //     cut ( 2, 5 ):     abghi0            position 6 moved right to position 3
  7. //                                        new length n=5.
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "dblib.h"
  11.  
  12. String&  String::cut ( int start, int stop )
  13.     {
  14.     
  15.     register int  sn = n;
  16.     if ( stop == -1 ) stop = sn-1;                        // excl. \0 at end.
  17.     if (!( sn <= stop || stop < 0 || stop < start ) )     // bounds are OK
  18.         {
  19.         if  ( stop != start )        // if they're equal, no cut necessary
  20.             {
  21.             slide (start, stop );    
  22.             }
  23.         }
  24.     return *this;
  25.     }
  26.     
  27. //------------------ end STRPPCUT.CPP --------------------